<?php
// +----------------------------------------------------------------------
// | Author: heizai <876555425@qq.com>
// +----------------------------------------------------------------------
namespace plugins\hz_msg_borad;
use cmf\lib\Plugin;
use plugins\hz_msg_borad\model\PluginMessageModel;
class HzMsgBoradPlugin extends Plugin
{

	public $info = [
		'name'        => 'HzMsgBorad',//Demo插件英文名，改成你的插件英文就行了
		'title'       => 'Message Board',
		'description' => 'Message Board',
		'status'      => 1,
		'author'      => 'Samonly',
		'version'     => '1.1',
		'demo_url'    => '',
		'author_url'  => ''
	];

	public $hasAdmin = 1;//插件是否有后台管理界面

	// 插件安装
	public function install()
	{
		$model = new PluginMessageModel();
		$prefix = config('database.prefix');
		$sql = <<<sql
      CREATE TABLE `cmf_plugin_guestbook`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `cat_id` int(11) NOT NULL COMMENT '分类ID',
  `firstName` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '名字',
  `lastName` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '姓氏',
  `company` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '公司',
  `fax` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '传真',
  `phone` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '手机',
  `email` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '邮箱',
  `title` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '标题',
  `msg` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '内容',
  `address` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '地址',
  `status` smallint(2) NOT NULL DEFAULT 1 COMMENT '留言状态，1：正常，0：删除',
  `ip_address` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'ip地址',
  `robot` tinyint(1) NOT NULL COMMENT '是否是机器人',
  `type` tinyint(1) NOT NULL COMMENT '是否报名',
  `date` datetime NOT NULL COMMENT '时间',
  `createtime` datetime NOT NULL COMMENT '时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = MyISAM AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '留言表' ROW_FORMAT = Dynamic;
sql;
		$model->execute($sql);

		return true;//安装成功返回true，失败false
	}

	// 插件卸载
	public function uninstall()
	{
		$model = new PluginMessageModel();
		$prefix = config('database.prefix');
		$sql = <<<sql
		DROP  TABLE  {$prefix}plugin_guestbook;
sql;
		$model->execute($sql);

		return true;//卸载成功返回true，失败false
	}

	//实现的footer_start钩子方法
	public function guestbook($param)
	{
		$config = $this->getConfig();
		$this->assign($config);
		echo $this->fetch('widget');
	}

	//实现的footer_start钩子方法
	public function guestbookcat($param)
	{
		$config = $this->getConfig();
		$this->assign($config);
		echo $this->fetch('widgetone');
	}

}